//
//  QQLogInWindowController.m
//  MacDevTest
//
//  Created by lbxia on 2020/8/15.
//  Copyright © 2020 com.lbx. All rights reserved.
//

#import "QQLogInWindowController.h"
#import "QQMainChatWindow.h"
#import "QQWindowManage.h"
#import "QQChatViewController.h"
#import "QQLogInSettingViewController.h"

@interface QQLogInWindowController ()
@property (weak) IBOutlet NSView *hiddenView;
@property (weak) IBOutlet NSView *topBackView;
@property (weak) IBOutlet NSButton *dropBtn;
@property (nonatomic, assign) BOOL expand;
@property (weak) IBOutlet NSImageView *userImageView;
@property (nonatomic, strong) NSWindow *subWindow;

@end

@implementation QQLogInWindowController

- (void)windowDidLoad {
    [super windowDidLoad];
    
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    
    CGRect frame = self.window.frame;
       
    frame.size.height -= 100;
           
    [self.window setFrame:frame display:YES animate:NO];
    
    self.expand = NO;
    
    _userImageView.wantsLayer = YES;
    _userImageView.layer.cornerRadius = 50;
    _userImageView.layer.backgroundColor = [NSColor whiteColor].CGColor;
    _userImageView.layer.borderWidth = 0.5;
    _userImageView.layer.borderColor = [NSColor greenColor].CGColor;
    
    self.window.contentView.wantsLayer = YES;
    
    self.window.contentView.layer.backgroundColor = [NSColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:0].CGColor;
    
    [self.window center];
    
}

- (IBAction)showorHidde:(id)sender {
    
    
    if (!_subWindow) {
        
        CGRect frame = self.window.frame;
           self.subWindow = [[NSWindow alloc]initWithContentRect:NSMakeRect(frame.origin.x, frame.origin.y - 75, frame.size.width, 75) styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:YES];
           
           QQLogInSettingViewController *setupViewController = [[QQLogInSettingViewController alloc]initWithNibName:@"QQLogInSettingViewController" bundle:[NSBundle mainBundle]];
           
           _subWindow.contentViewController = setupViewController;
        
//        self.window
        
//        [NSAnimation ani]
        
//        [NSWindow]
        
           [self.window addChildWindow:_subWindow ordered:NSWindowBelow];
    }
    else
    {
        [self.window removeChildWindow:_subWindow];
        [_subWindow setFrame:NSZeroRect display:NO];
        self.subWindow = nil;
    }
    
   
    
    
//    CGRect frame = self.window.frame;
//
//    frame.size.height += 100*(_expand ? -1:1);
//
//    [self.window setFrame:frame display:NO animate:YES];
//
    _expand = !_expand;

    [_dropBtn setImage:[NSImage imageNamed:_expand ? @"loginUp" : @"loginDown"]];
}


- (IBAction)LogIn:(id)sender {
    
    
    QQMainChatWindow *qqMainWindow = [[QQMainChatWindow alloc]initWithWindowNibName:@"QQMainChatWindow"];
    
    [QQWindowManage sharedManager].qqMainChatWindow = qqMainWindow;
    
    [qqMainWindow.window makeKeyAndOrderFront:nil];
    
    [self.window close];
    [QQWindowManage sharedManager].qqLogWindow = nil;

}

- (void)dealloc
{
    NSLog(@"QQLogInWindowController dealloc");
}

@end
